package team.yidong.fenda.controller;

import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import team.yidong.fenda.service.HospitalScheduleService;

import javax.servlet.http.HttpSession;
import java.text.ParseException;

/**
 * Created by xuanlong on 2018/3/30.
 */
@Controller
public class HospitalScheduleController {
    @Autowired
    HospitalScheduleService hospitalScheduleService;

    @RequestMapping("/hospitalSchedule")
    public String hospitalSchedule() {
        return "hospitalSchedule";
    }

    @RequestMapping("/findHospitalSchedule")
    @ResponseBody
    public JSONArray findHospitalSchedule(HttpSession session, String date) {
        Integer hospitalId = (Integer) session.getAttribute("loginHospitalId");
        return hospitalScheduleService.findAll(hospitalId, date);
    }

    @RequestMapping("/addHospitalSchedule")
    @ResponseBody
    public String addHospitalSchedule(HttpSession session, @RequestParam Integer peopleNum, @RequestParam String dayTime, @RequestParam String msg1, String msgDate, String msg2) throws ParseException {
        Integer hospitalId = (Integer) session.getAttribute("loginHospitalId");
        return hospitalScheduleService.addSchedule(hospitalId, peopleNum, dayTime, msg1, msgDate, msg2);
    }

    @RequestMapping("/updateSchedule")
    @ResponseBody
    public void updateSchedule(@RequestParam Integer scheduleId, @RequestParam String msg1, String msgDate, String msg2) {
        hospitalScheduleService.updateSchedule(scheduleId, msg1, msgDate, msg2);
    }

    @RequestMapping("/findScheduleStatus")
    @ResponseBody
    public String findScheduleStatus(HttpSession session) {
        Integer hospitalId = (Integer) session.getAttribute("loginHospitalId");
        return hospitalScheduleService.findScheduleStatus(hospitalId);
    }

    @RequestMapping("/updateScheduleStatus")
    @ResponseBody
    public void updateScheduleStatus(HttpSession session, @RequestParam String status) {
        Integer hospitalId = (Integer) session.getAttribute("loginHospitalId");
        hospitalScheduleService.updateScheduleStatus(hospitalId, status);
    }
}
